<?php

/**
 * Loads Settings file
 *
 * @return SimpleXML
 */
function squareit_gsp_load_settings($reset=false)
{
	$sqr_gsp_settings = '';
	if (!isset($_SESSION['SQR_GSP']) || $reset)
	{
		if (file_exists(GSP_DATAPATH.'settings.xml'))
		{
			$sqr_gsp_settings = getXML(GSP_DATAPATH.'settings.xml');
			$_SESSION['SQR_GSP'] = squareit_objectsintoarray($sqr_gsp_settings);

			$_SESSION['SQR_GSP']['sess_time'] = time()+(60*60);
			$sqr_gsp_settings = $_SESSION['SQR_GSP'];
		}
		else
		{
			squareit_msg_box(GSP_PLUGINID." - Problem Loading settings file");
			exit;
		}
	}
	else
	{
		//refresh session every hour
		if ( time() > $_SESSION['SQR_GSP']['sess_time'])
		{
			squareit_gsp_load_settings(true);
		}

		$sqr_gsp_settings = $_SESSION['SQR_GSP'];
	}

	return $sqr_gsp_settings;
}


//credit hook
if (function_exists('add_action'))
{
    add_action(GSP_PLUGINID.'-sidebar-extra', 'squareit_gsp_credit', array());
}
function squareit_gsp_credit()
{
	?>
	<div style="text-align:center; font-size:11px;">
	Plugin By: <a href="http://www.squareitsol.com" target="_blank">Square It Solutions</a>
	</div>
	<?php
}

function squareit_gsp_security()
{
	global $SESSIONHASH;
	if (@$_REQUEST['s'] !== $SESSIONHASH)
	{
		die("INVALID REQUEST");
	}
}
